package init

import (
	"flag"
	"gateway/basic/config"
	"gateway/untils"
	"log"

	__ "gateway/basic/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func InitsGrpc() {
	address := "14.103.175.162:8500"
	consulClient, err := untils.NewConsulClient(address)
	if err != nil {
		panic(err)
	}
	cfg := untils.GRPCService{
		Name:    "service",
		Tags:    []string{"service"},
		Address: "127.0.0.1",
		Port:    50051,
	}
	err = consulClient.RegisterService(&cfg)

	flag.Parse()
	addr := "127.0.0.1:50051"
	conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	config.ClassClient = __.NewClassClient(conn)
}
